<template>
    <div class="body">
        <section class="main-content">
            <h1 id="编译与安装">GMSSL编译与安装</h1>

            <h2 id="在linux和mac下的编译和安装">在Linux和Mac下的编译和安装</h2>

            <div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>./config
make
make <span class="nb">test
sudo </span>make <span class="nb">install</span>
</code></pre></div></div>

            <h2 id="在window下的编译和安装">在Window下的编译和安装</h2>

            <p>安装ActivePerl和Visual Studio，以管理员身份打开Visual Studio Tools下的Developer Command Prompt控制台并运行：</p>

            <div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>perl Configure VC-WIN32
nmake
nmake <span class="nb">install</span>
</code></pre></div></div>

            <p>下面是一些常见的编译错误及原因：</p>

            <ol>
                <li>安装最新的Visual Studio版本，不要使用Visual C++ 6、Visual Studio 2008。</li>
                <li>确保从一份干净的（没有已经编译出来的对象文件或汇编文件）最新Master分支源代码开始编译。</li>
                <li>编译系统没有找到<code class="language-plaintext highlighter-rouge">nmake</code>。实际上<code class="language-plaintext highlighter-rouge">nmake</code>是Visual Studio自带的工具，不需要单独安装。编译系统无法找到<code class="language-plaintext highlighter-rouge">nmake</code>的原因是没有在Visual Studio的命令行环境下执行编译指定。</li>
                <li>无法执行<code class="language-plaintext highlighter-rouge">nmake install</code>。这个命令需要以管理员的身份执行。</li>
                <li>对象文件(<code class="language-plaintext highlighter-rouge">.obj</code>)和目标平台不一致，通常是由于在Visual Studio的32位控制台下执行<code class="language-plaintext highlighter-rouge">perl Configure VC-WIN64A</code>；或者在Visual Studio的64位控制台下执行<code class="language-plaintext highlighter-rouge">perl Configure VC-WIN32</code>导致的。</li>
            </ol>

            <h2 id="编译android目标文件">编译Android目标文件</h2>

            <p>针对Android/ARM目标平台，需要先安装Android SDK/NDK。设置交叉编译环境后，可以直接用GmSSL内置的编译系统进行编译。下面的脚本给出了交叉编译的示例，需要根据安装的SDK位置及预计的平台编号修改<code class="language-plaintext highlighter-rouge">ANDROID_PATH</code>和<code class="language-plaintext highlighter-rouge">PLATFORM_VERSION</code>的值。</p>

            <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#!/bin/bash</span>

<span class="nv">ANDROID_PATH</span><span class="o">=</span>/path/to/android/sdf/
<span class="nv">PLATFORM_VERSION</span><span class="o">=</span>22

<span class="nv">MAKE_TOOLCHAIN</span><span class="o">=</span><span class="nv">$ANDROID_PATH</span>/sdk/ndk-bundle/build/tools/make-standalone-toolchain.sh
<span class="nb">export </span><span class="nv">TOOLCHAIN_PATH</span><span class="o">=</span><span class="nv">$ANDROID_PATH</span>/android-toolchain-arm
<span class="nv">$MAKE_TOOLCHAIN</span> <span class="nt">--arch</span><span class="o">=</span>arm <span class="nt">--platform</span><span class="o">=</span>android-<span class="nv">$PLATFORM_VERSION</span> <span class="nt">--install-dir</span><span class="o">=</span><span class="nv">$TOOLCHAIN_PATH</span>

<span class="nb">export </span><span class="nv">MACHINE</span><span class="o">=</span>armv7
<span class="nb">export </span><span class="nv">SYSTEM</span><span class="o">=</span>android
<span class="nb">export </span><span class="nv">ARCH</span><span class="o">=</span>arm
<span class="nb">export </span><span class="nv">CROSS_SYSROOT</span><span class="o">=</span><span class="nv">$TOOLCHAIN_PATH</span>/sysroot
<span class="nb">export </span><span class="nv">TOOL_BASENAME</span><span class="o">=</span><span class="nv">$TOOLCHAIN_PATH</span>/bin/arm-linux-androideabi
<span class="nb">export </span><span class="nv">CC</span><span class="o">=</span><span class="nv">$TOOL_BASENAME</span><span class="nt">-gcc</span>
<span class="nb">export </span><span class="nv">CXX</span><span class="o">=</span><span class="nv">$TOOL_BASENAME</span><span class="nt">-g</span>++
<span class="nb">export </span><span class="nv">LD</span><span class="o">=</span><span class="nv">$TOOL_BASENAME</span><span class="nt">-ld</span>
<span class="nb">export </span><span class="nv">LINK</span><span class="o">=</span><span class="nv">$CXX</span>
<span class="nb">export </span><span class="nv">AR</span><span class="o">=</span><span class="nv">$TOOL_BASENAME</span><span class="nt">-ar</span>
<span class="nb">export </span><span class="nv">RANLIB</span><span class="o">=</span><span class="nv">$TOOL_BASENAME</span><span class="nt">-ranlib</span>
<span class="nb">export </span><span class="nv">STRIP</span><span class="o">=</span><span class="nv">$TOOL_BASENAME</span><span class="nt">-strip</span>

./config
make
</code></pre></div></div>

            <p>编译完成后，可以生成面向Android目标平台的二进制库和<code class="language-plaintext highlighter-rouge">gmssl</code>可执行程序。</p>

            <p>如需调用GmSSL的Java API，可以参考Android NDK的示例。</p>

            <h2 id="编译iphone-os目标文件">编译iPhone OS目标文件</h2>

            <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>export CC=clang
export CROSS_TOP=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
export CROSS_SDK=iPhoneOS.sdk
export PATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:$PATH"
./Configure ios64-cross no-shared --prefix=/usr/local/openssl-ios64
make
</code></pre></div></div>

            <h2 id="编译java接口">编译Java接口</h2>

            <p>由于GmSSL编译脚本还不能实现在所有操作系统上自动编译Java接口代码，因此编译脚本中默认没有启用Java接口的编译。
                开启方式如下：
                在源代码根目录下找到<code class="language-plaintext highlighter-rouge">Configure</code>文件，找到</p>

            <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$config{dirs} = [ "crypto", "ssl", "engines", "apps", "util", "tools", "fuzz", "test" ];
</code></pre></div></div>
            <p>这一行，并将其修改为</p>
            <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$config{dirs} = [ "crypto", "ssl", "engines", "apps", "util", "tools", "fuzz", "test", "java" ];
</code></pre></div></div>

            <p>重新编译，则可以自动编译<code class="language-plaintext highlighter-rouge">java</code>目录下的C代码和Java代码，并生成<code class="language-plaintext highlighter-rouge">libgmssljni</code>动态库和<code class="language-plaintext highlighter-rouge">GmSSL.class</code>。
                这个模块的编译目前在Mac下可以测试通过。</p>

        </section>
    </div>
</template>

<script>
    export default {
        name: "buildcpp-doc"
    }
</script>

<style scoped lang="less">
    @import "style.less";
</style>
